package 
{
	import b4.model.basic.*;
	import b4.model.player.*;
	import b4.net.*;
	import b4.scene.basic.*;
	import b4.scene.load.*;
	import b4.scene.town.TownScene;
	import b4.util.profile.*;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	[SWF(width='1250', height='650', backgroundColor='#CECAB1', frameRate='30')]
	public class B4dev extends Sprite
	{
		public function B4dev()
		{
			GameProfile.stageWidth = stage.stageWidth;
			GameProfile.stageHeight = stage.stageHeight;
			//本地调试用
			if (!GameProfile.RELEASE)
			{
				GameProfile.setPlatform();
			}
			else
			{
				var param:Object = loaderInfo.parameters;
				GameProfile.setPlatform();
			}
			addChild(SceneManager.getInstance());
			startLoadResource();
		}
		
		private function startLoadResource():void
		{
			//开始加载主资源
			var rm:ResourceManager = ResourceManager.getInstance();
			var resourceLoader:ResourceLoader = rm.loadResources(["main_resource.swf"]);
			resourceLoader.addEventListener(Event.COMPLETE, onResourceLoaded, false, 0, true);
			var loadScene:MainLoadScene = new MainLoadScene(resourceLoader);
			SceneManager.getInstance().loadScene(loadScene);
		}
		
		private function onResourceLoaded(event:Event):void
		{
			//登陆用户
			var me:Me = new Me();
			me.login("1000");
			me.addEventListener(ModelEvent.LOGIN_COMPLETE, onLoginComplete, false, 0, true);
		}
		
		private function onLoginComplete(event:ModelEvent):void
		{
			//加载主城
			var townScene:TownScene = TownScene.getInstance();
			var me:Me = PlayerManager.getInstance().me;
			townScene.loadTown(me.townList[me.mainTownId]);
			SceneManager.getInstance().loadScene(townScene);
		}
		
	}
}
